
// 只在金宝博下运行
function getDomainFromUrl(url){
	var host = "null";
	if(typeof url == "undefined" || null == url){
		url = window.location.href;
	}
	
	var regex = /.*\:\/\/([^\/]*).*/;
	var match = url.match(regex);
	if(typeof match != "undefined" && null != match){
		host = match[1];
	}
	
	return host;
}

function checkForValidUrl(tabId, changeInfo, tab) {
	if(getDomainFromUrl(tab.url).toLowerCase() == "www.188bet.com"){
		chrome.pageAction.show(tabId);
	}
};

chrome.tabs.onUpdated.addListener(checkForValidUrl);


// 接收 content_script.js 发出的消息
var bet_info = {};
bet_info.total = 0;
bet_info.extensionerr = '';
chrome.runtime.onMessage.addListener(function(request, sender, sendRequest){
	if (request.betre == 'succ'){
        bet_info.total += 1;
    }
	if (request.extensionerr != 'undefined'){
		bet_info.extensionerr = request.extensionerr;
	}else{
		bet_info.extensionerr = '';
	}
});
